import BaseUtil from '@/BaseUtil';
import BuffUtil from '@/BuffUtil';
import { OrderId } from '@/globals/order';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 神圣冲击
 **/
export default class MS_HolyStrike extends AbilityBase {
    static instance: MS_HolyStrike;
    buffType: AppBuffType = {
        id: 'buff_MS_HolyStrike',
        art: this.art,
        name: this.abilityName,
        ubertip: '受到了大量的减速',
        dur: 3,
        attribute: {
            move_speed_p: -0.5,
            attackSpd_p: 1,
        },
        targetArt: 'Abilities\\Spells\\Human\\Slow\\SlowCaster.mdl',
        targetAttach: 'origin',
    };
    constructor(id: string) {
        super(id);
        MS_HolyStrike.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        BaseUtil.onTimer(0.5, (c) => {
            let order = GetUnitCurrentOrder(source);
            if (order != OrderId.Soulpreservation) return false;
            MovementCommon.LineMissile({
                missile: 'Abilities\\Spells\\Human\\HolyBolt\\HolyBoltMissile.mdl',
                angle: GetUnitFacing(source),
                distance: 600,
                caster: source,
                speed: 600,
                radius: 75,
                onHit: this.onMissileHit.bind(this),
                tag: 'all',
            });
            return c < 6;
        });
    }
    onMissileHit(p: LineMissileConfig, hit: unit) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 32 * lv + UnitCommon.取法强(p.caster) * (0.5 + 0.3 * lv);
        if (IsUnitEnemy(hit, GetOwningPlayer(p.caster))) {
            DamageSystemInstance.applyLightDamage(hit, p.caster, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Items\\StaffOfPurification\\PurificationCaster.mdl', hit, 'origin'));
            // BuffUtil.addBuff(hit, this.buffType.id, p.caster);
            BuffCommon.addBuff({ target: hit, caster: p.caster, buffTypeId: this.buffType.id, ablityId: this.id });
        } else {
            DamageSystemInstance.applyHeal(hit, p.caster, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl', hit, 'overhead'));
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
